package basic.study.algorithms.struct;

/**
 * @author Kevin
 * @date 2020/2/26 14:02
 */
public class QueueBasedLinkedList {
    private Node head = null;
    private Node tail = null;

    public void enqueue(String value) {
        if (head == null) {
            Node n = new Node(value, null);
            head = n;
            tail = n;
        } else {
            Node n = new Node(value, null);
            tail.next = n;
            tail = n;
        }
    }

    public String dequeue() {
        if (head == null) return null;

        String value = head.data;
        head = head.next;
        if (head == null) tail = null;
        return value;
    }


    class Node {
        private Node next;
        private String data;
        Node (String data, Node next) {
            next = next;
            data = data;
        }
        public String getData() {
            return data;
        }
    }
}
